package system

import (
	"gorm.io/datatypes"
	"server/global"
)

//系统角色表
type SysRole struct {
	global.GvaModel
	ID          uint            `gorm:"column:id;primaryKey;autoIncrement;comment:角色ID" json:"id"`
	ParentId    uint            `gorm:"column:parent_id;comment:父级角色ID"       json:"parent_id" form:"parent_id"`
	Name        string          `gorm:"column:name;unique;comment:角色定义名"     json:"name" form:"name" binding:"required"`
	DisplayName string          `gorm:"column:display_name;comment:角色显示名"    json:"display_name" form:"display_name" binding:"required"`
	PermIds     datatypes.JSON  `gorm:"column:perm_ids;comment:角色权限数据，方便编辑"        json:"perm_ids" form:"perm_ids" binding:"dive,required"`
	Description string          `gorm:"column:description;comment:角色描述"     json:"description" form:"description"`
	OrderNum    uint            `gorm:"column:order_num;comment:排序数字，值越小越靠前"       json:"order_num" form:"order_num" binding:"min=0"`
	Permission  []SysPermission `gorm:"many2many:sys_permission_role;foreignKey:ID;joinForeignKey:SysRoleId;References:ID;joinReferences:SysPermId" json:"permission" binding:"-"`
	Children    []*SysRole      `gorm:"-" json:"children" binding:"-"` //子角色列表
}
